import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)
export default new Vuex.Store({
    state: { // 仓库存储的数据
        //isAuthenticated: localStorage.getItem('authToken') !== null
        isAuthenticated: false
    },
    mutations: { // 唯一修改state的方法
        login(state, token) {
            localStorage.setItem('authToken', token)
            state.isAuthenticated = true
        },
        logout(state) {
            localStorage.removeItem('authToken')
            state.isAuthenticated = false
        }
    }
})